package NC;

public class NC44 {
    public boolean isMatch(String s, String p) {
        boolean[][] dp = new boolean[s.length() + 1][p.length() + 1]; // rowindex-->被匹配的字符串的第i个char,colindex-->匹配字符串的第i个char
        boolean[] dp2 = new boolean[s.length()+1];
        dp[0][0] = true;

        for (int i = 1; i < p.length()+1; i++) {
            dp[0][i] = dp[0][i-1]&&(p.charAt(i-1)=='*');
        }
        for (int i = 0; i < s.length(); i++)
            for (int j = 0; j < p.length(); j++) {
                if (p.charAt(j) == s.charAt(i) || p.charAt(j) == '?')
                    dp[i + 1][j + 1] = dp[i][j];
                else if (p.charAt(j) == '*') {
                    dp[i + 1][j + 1] = dp[i][j] || dp[i + 1][j] || dp[i][j + 1];
                }
            }
        return dp[s.length()][p.length()];
    }
}


class Test5{
    public static void main(String[] args) {
        NC44 nc44 = new NC44();
        System.out.println(nc44.isMatch("aab", "c*a*b"));
    }
}